package com.progark.sound.controller;

import sheep.game.State;
import sheep.input.TouchListener;

import android.content.res.Resources;
import android.graphics.Canvas;
import android.view.MotionEvent;

import com.progark.sound.model.GameModel;
import com.progark.sound.model.Player;
import com.progark.sound.view.GameView;

public class GameController extends State implements TouchListener{
	
	private GameModel gameModel;
	private GameView gameView;
	private Player player1, player2;
	private Resources resources;
	

	public GameController(Player player1, Player player2, Resources resources){
		this.player1 = player1;
		this.player2 = player2;
		gameView = new GameView(this);
		gameModel = new GameModel(player1, player2, resources);
		this.resources = resources;
	}
	
	public void draw(Canvas canvas){
		endGame();
		gameView.draw(canvas);
	}
	
	
	public void endGame(){
		if(gameModel.isGameFinished()){
			getGame().popState();
			getGame().pushState(new ResultsController(player1, player2, resources));
		}
	}
	
	public GameModel getModel(){
		return gameModel;
	}
	
	public boolean onTouchDown(MotionEvent event) {
		return gameView.onTouchDown(event);
	}
	
	
	

	

}
